package com.es.hr.shopscore;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

import com.es.business.area.AreaBean;
import com.es.business.area.AreaBiz;
import com.es.business.city.CityBean;
import com.es.business.city.CityBiz;
import com.es.business.citys.CitysBean;
import com.es.business.citys.CitysBiz;
import com.es.business.province.ProvinceBean;
import com.es.business.province.ProvinceBiz;
import com.es.hr.emp.EmpInfoBean;
import com.es.hr.shop.ShopBean;
import com.es.hr.shop.ShopBiz;
import com.es.util.page.PageBean;
import com.opensymphony.webwork.interceptor.ServletRequestAware;
import com.opensymphony.xwork.ActionSupport;

public class ShopScoreSearchDoAction extends ActionSupport
implements ServletRequestAware{
	 HttpServletRequest request;

	public void setServletRequest(HttpServletRequest paramHttpServletRequest) {
		// TODO Auto-generated method stub
		this.request = paramHttpServletRequest;
	}
	
	public String execute() throws Exception{
		String result = "";
		ShopScoreBiz shopScoreBiz = new ShopScoreBiz();
		String area_code = (request.getParameter("emp_area_code")==null)?"":request.getParameter("emp_area_code");
		String province_code = (request.getParameter("emp_province_code")==null)?"":request.getParameter("emp_province_code");
		String city_code = (request.getParameter("emp_city_code")==null)?"":request.getParameter("emp_city_code");
		
		String queryShopCode = (request.getParameter("queryShopCode")==null)?"":request.getParameter("queryShopCode");
		String queryShopName = (request.getParameter("queryShopName")==null)?"":request.getParameter("queryShopName");
		String starttime = (request.getParameter("starttime")==null)?"":request.getParameter("starttime");
		String endtime = (request.getParameter("endtime")==null)?"":request.getParameter("endtime");
		String curp = (request.getParameter("curpage")==null)?"1":request.getParameter("curpage");
		int curpage = Integer.parseInt(curp);
				
		ArrayList<String> query = new ArrayList<String>();
		query.add( queryShopCode);
		query.add( queryShopName);	
		query.add(area_code);
		query.add( province_code);
		query.add( city_code);

		
		PageBean res = shopScoreBiz.searchShopScoreWithShop(starttime,endtime,query, curpage);

		this.request.setAttribute("pageBean", res);
		this.request.setAttribute("areaList", new AreaBiz().getAreaList());
		this.request.setAttribute("emp_area_code", area_code);
		this.request.setAttribute("emp_province_code", province_code);
		this.request.setAttribute("emp_city_code", city_code);
		this.request.setAttribute("queryShopCode", queryShopCode);
		this.request.setAttribute("queryShopName", queryShopName);
		this.request.setAttribute("starttime", starttime);
		this.request.setAttribute("endtime", endtime);
		
		if(area_code != null && area_code.length() > 0){
			this.request.setAttribute("provinceList", new ProvinceBiz().getProvinceByAreaCode(area_code));
		}
		if(province_code != null && province_code.length() > 0){
			this.request.setAttribute("cityList", new CityBiz().getCityByProvinceCode(province_code));
		}
		
		result = "success";
		return result;
	}
	
	private void shopInfoBeanSet(HashMap<String, Object> map, ShopBean bean) throws SecurityException, ClassNotFoundException, IllegalArgumentException, IllegalAccessException{
		Field[] fds = Class.forName("com.es.hr.shop.ShopBean").getDeclaredFields();   
		
		for(int i=0;i<fds.length;i++){   
				map.put(fds[i].getName(), fds[i].get(bean));
		}
	}

}
